package com.df.my_net_game.common.utils;

//import javax.validation.ConstraintViolation;
//import javax.validation.Validation;
//import javax.validation.Validator;
import java.util.Iterator;
import java.util.Set;

public class ValidationUitl {
    private ValidationUitl() { }

//    private static Validator validator;
//    static {
//        validator = Validation.buildDefaultValidatorFactory().getValidator();
//    }
//
//    /**
//     * 校验对象
//     *
//     * @param object 待校验对象
//     * @param groups 待校验的组
//     */
//    public static void validateEntity(Object object, Class<?>... groups) throws Exception {
//        Set<ConstraintViolation<Object>> constraintViolations = validator.validate(object, groups);
//
//        if (!constraintViolations.isEmpty()) {
//            Iterator<ConstraintViolation<Object>> iterator = constraintViolations.iterator();
//            StringBuilder msg = new StringBuilder();
//            while (iterator.hasNext()) {
//                ConstraintViolation<Object> constraint = iterator.next();
//                msg.append(constraint.getMessage()).append(',');
//            }
//            throw new RuntimeException(msg.toString().substring(0,msg.toString().lastIndexOf(',')));
//        }
//    }

}
